// import Vue from 'vue';
import * as types from "../types";
import axios, { fetchPost } from "./../../utils/axiosHttp";

export default {
  state: {
    model: {},
    title: "",
    page: {
      data: [],
      total: 0,
      pageNum: 0,
      pageSize: 0,
      loading: true
    }
  },
  mutations: {
    [types.TEST01]: (state, data) => {
      state.title = data.title;
      state.model = data;
    },
    [types.TEST02]: (state, data) => {
      state.page.data = data.list;
      state.page.total = data.total;
      state.page.pageNum = data.pageNum;
      state.page.pageSize = data.pageSize;
      state.page.loading = false;
    }
  },
  // 触发事件
  actions: {
    one({ commit }, data) {
      commit(types.TEST01, data);
    },
    two({ commit }, param) {
      let token = {
        tokenId: "12345"
      };
      let url = "/Api/login";
      let rs = fetchPost(url, param, token);

      rs.then(val => {
        console.log("exec", val.result);
        commit(types.TEST02, val.result);
      }).catch(error => {
        commit(types.TEST02, {});
        console.log("exec error msg", error);
      });
    }
  }
};
